package dst.ass1.jpa.model.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;

import dst.ass1.jpa.model.IMembership;
import dst.ass1.jpa.model.ITaskForce;
import dst.ass1.jpa.model.IWorkPlatform;

@Entity
public class WorkPlatform implements IWorkPlatform{

	private final static Logger LOGGER = Logger.getLogger(WorkPlatform.class.getName());
	
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;
	
	@Column(unique = true)			//Name have to be unique
	private String name;
	
	private String location;
	private BigDecimal costsPerWorkUnit;
	
	@OneToMany(targetEntity = Membership.class,mappedBy = "workPlatform",cascade = CascadeType.ALL,fetch=FetchType.LAZY)  //to-star(collection) props are loaded lazily (as the number of items may well be very large
	private List<IMembership> memberships;
	
	@OneToMany(targetEntity = TaskForce.class, cascade = CascadeType.ALL, mappedBy = "workPlatform",fetch=FetchType.LAZY)  //to-star(collection) props are loaded lazily (as the number of items may well be very large
	private List<ITaskForce> taskForces;
	
	public WorkPlatform (){
		this.memberships= new ArrayList<IMembership>();
		this.taskForces= new ArrayList<ITaskForce>();
	}
	
	@Override
	public Long getId() {
		return id;
	}
	
	@Override
	public void setId(Long id) {
		this.id = id;
	}
	
	@Override
	public String getName() {
		return name;
	}
	
	@Override
	public void setName(String name) {
		this.name = name;
	}
	
	@Override
	public String getLocation() {
		return location;
	}
	
	@Override
	public void setLocation(String location) {
		this.location = location;
	}
	
	@Override
	public BigDecimal getCostsPerWorkUnit() {
		return costsPerWorkUnit;
	}
	
	@Override
	public void setCostsPerWorkUnit(BigDecimal costsPerWorkUnit) {
		this.costsPerWorkUnit = costsPerWorkUnit;
	}
	
	@Override
	public List<ITaskForce> getTaskForces() {
		return taskForces;
	}
	
	@Override
	public void setTaskForces(List<ITaskForce> taskForces) {
		this.taskForces = taskForces;
	}
	
	@Override
	public void addMembership(IMembership membership) {
		if(this.memberships!=null){
			this.memberships.add(membership);
		}
		else{
			LOGGER.info("WorkPlatform.List<IMembership> was null");
		}
	}
	
	@Override
	public void setMemberships(List<IMembership> memberships) {
		this.memberships=memberships;
		
	}
	
	@Override
	public void addTaskForce(ITaskForce taskForce) {
		if(this.taskForces!=null){
			this.taskForces.add(taskForce);
		}
		else{
			LOGGER.info("WorkPlatform.List<ITaskForce> was null");
		}
	}
	
	@Override
	public List<IMembership> getMemberships() {
		return this.memberships;
	}
	
	
	

}
